package cn.sanxintong.core;


import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;

import cn.sanxintong.dbutility.DbUtility;
import cn.sanxintong.entity.constant.Constant;
import cn.sanxintong.utils.generate.ControllerUtil;
import cn.sanxintong.utils.generate.DAOUtil;
import cn.sanxintong.utils.generate.DTOUtil;
import cn.sanxintong.utils.generate.IServiceUtil;
import cn.sanxintong.utils.generate.MapperUtil;
import cn.sanxintong.utils.generate.ModelUtil;
import cn.sanxintong.utils.generate.ServiceImplUtil;


/**
 * 自动生成主程序
 * @author hxy
 * @version 1.0.0
 */
public class CodeGenerateUtils {
    
	/**
	 * 主入口
	 * @param args
	 * @throws Exception
	 */
    public static void main(String[] args) throws Exception{
        CodeGenerateUtils codeGenerateUtils = new CodeGenerateUtils();
        codeGenerateUtils.generate();
    }
    
    /**
     * 连接表生成代码
     * @throws Exception
     */
    public void generate() throws Exception{
    	String str = null;
        try {
            Connection connection = DbUtility.getConnection();
            DatabaseMetaData databaseMetaData = connection.getMetaData();
            ResultSet pkRSet = databaseMetaData.getPrimaryKeys(null, null, Constant.TABLEN_NAME); 
            ResultSet resultSet = databaseMetaData.getColumns(null,"%", Constant.TABLEN_NAME,"%");
            while (pkRSet.next()) {
        	   str = (String) pkRSet.getObject(4); 
			}
            //生成mapper
            //MapperUtil.generateMapperFile(resultSet,str);
            //生成Model文件-----1.只需要配置好包名即可
            ModelUtil.generateModelFile(resultSet);
            //生成DTO
            //DTOUtil.generateDTOFile(resultSet);
            //生成Controller
            //ControllerUtil.generateControllerFile(resultSet,str);
            //生成DAO
            //DAOUtil.generateDaoFile(resultSet);
            //生成IService
            //IServiceUtil.generateServiceInterfaceFile(resultSet);
            //生成ServiceImpl
            ServiceImplUtil.generateServiceImplFile(resultSet);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally{

        }
    }
}

